"""
https://leetcode.cn/problems/nth-highest-salary/description/?envType=study-plan-v2&envId=30-days-of-pandas&lang=pythondata

177. 第N高的薪水
中等
相关标签
premium lock icon
相关企业
SQL Schema
Pandas Schema
表: Employee

+-------------+------+
| Column Name | Type |
+-------------+------+
| id          | int  |
| salary      | int  |
+-------------+------+
id 是该表的主键（列中的值互不相同）。
该表的每一行都包含有关员工工资的信息。
 

编写一个解决方案查询 Employee 表中第 n 高的 不同 工资。如果少于 n 个不同工资，查询结果应该为 null 。

查询结果格式如下所示。

 

示例 1:

输入: 
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1  | 100    |
| 2  | 200    |
| 3  | 300    |
+----+--------+
n = 2
输出: 
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| 200                    |
+------------------------+
示例 2:

输入: 
Employee 表:
+----+--------+
| id | salary |
+----+--------+
| 1  | 100    |
+----+--------+
n = 2
输出: 
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| null                   |
+------------------------+

"""

import pandas as pd

def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame:
    sort_salaries=employee['salary'].drop_duplicates().sort_values(ascending=False)
    if len(sort_salaries)>=N and N>0:
        res_salary= sort_salaries.iloc[N-1]
    else:
        res_salary=None
    return pd.DataFrame([res_salary],columns=[f'getNthHighestSalary({N})'])

if __name__=='__main__':
    employee = pd.DataFrame([
      [1, 100],
      [2, 200],
      [3, 300],
    ],columns=['id','salary'])
    n = 3
    print(nth_highest_salary(employee, n))